#ifndef GAMMAMANAGERHELPER_H
#define GAMMAMANAGERHELPER_H

#include <QTime>

#include <QtMath>
#include <QDebug>
#include <QSizeF>
#include <QString>
#include <QX11Info>
#include <QObject>
#include <QDateTime>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>

#include "clib-syslog.h"
#include "gamma-manager-define.h"
#include "gamma-manager-adaptor.h"
#include "rgb-gamma-table.h"

#ifdef __cplusplus
extern "C" {
#endif
#include <math.h>
#include <X11/extensions/Xrandr.h>
#include <X11/Xatom.h>
#ifdef __cplusplus
}
#endif

class GmHelper: public QObject
{
    Q_OBJECT
public:
    GmHelper(QObject *parent = nullptr);
    ~GmHelper();

    //{"status":"success","country":"China","countryCode":"CN","region":"TJ","regionName":"Tianjin","city":"Tianjin","zip":"","lat":39.3434,"lon":117.362,"timezone":"Asia/Shanghai","isp":"ASN for TIANJIN Provincial Net of CT","org":"Chinanet TJ","as":"AS17638 ASN for TIANJIN Provincial Net of CT","query":"123.150.8.42"}
    bool getLonAndLatByJson(QString url, QByteArray bytes, QSizeF& psize);

    bool getLonAndLatIPAPI(QByteArray jsonBytes, QSizeF& psize);
     //{"location": {"lat": 39.9075, "lng": 116.3972}, "accuracy": 49000.0}
    bool getLonAndLatMozilla(QByteArray jsonBytes, QSizeF& psize);


    bool getSunriseSunset(QDateTime &rtDate,QSizeF &location, QSizeF &SunriseSunset);

    bool getRtSunriseSunset(QSizeF &location, QSizeF &SunriseSunset);
    bool getRgbWithTemperature(double temp, ColorRGB &result);
    void getRgbInterpolate(const ColorRGB &p1, const ColorRGB &p2, double index, ColorRGB &result);
    uint getTempInterpolate(const double svalue, const double bvalue, double value);
    uint getTemperatureWithRgb(const double red, const double green, const double blue);
    void setTemperature(const uint temp);
    void setBrightness(const uint brightness);
    OutputGammaInfoList getAllOutputGammaInfo();
    double hourMinuteToDouble(int hour, int minute);
private:
    double deg2rad (double degrees);
    double  rad2deg (double radians);


    XRRScreenResources  *m_pScreenRes = nullptr;
    uint m_brightness;
    uint m_temperature;
};

#endif // GAMMAMANAGERHELPER_H
